package com.ruoyi.asset.menu;

public enum ErrorCode {
    // 成功
    SUCCESS(0, "成功", "SUCCESS"),

    // 通用错误
    INVALID_PARAMETER(1001, "参数无效", "ERROR"),
    NULL_PARAMETER(1002, "参数为空", "ERROR"),
    UNKNOWN_ERROR(1003, "未知错误", "ERROR"),

    // 资产计算相关错误
    ASSET_ORIGINAL_VALUE_ERROR(2001, "资产原值不正确", "ERROR"),
    DEPRECIATION_METHOD_ERROR(2002, "不支持的折旧方法", "ERROR"),
    DEPRECIATION_YEAR_ERROR(2003, "折旧年限不合理", "ERROR"),
    IMPAIRMENT_AMOUNT_ERROR(2004, "减值金额错误", "ERROR"),
    DISCOUNT_AMOUNT_ERROR(2005, "折扣金额错误", "ERROR");


    // 枚举字段
    private final int code;
    private final String message;
    private final String status;

    // 私有构造函数
    ErrorCode(int code, String message, String status) {
        this.code = code;
        this.message = message;
        this.status = status;
    }

    // Getter 方法
    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public String getStatus() {
        return status;
    }

    // 根据错误码查找对应的枚举
    public static ErrorCode getByCode(int code) {
        for (ErrorCode errorCode : ErrorCode.values()) {
            if (errorCode.getCode() == code) {
                return errorCode;
            }
        }
        // 未找到时返回未知错误
        return UNKNOWN_ERROR;
    }

    // 示例用法
    public static void main(String[] args) {
        // 获取错误信息
        ErrorCode error = ErrorCode.INVALID_PARAMETER;
        System.out.println("错误码: " + error.getCode());
        System.out.println("错误描述: " + error.getMessage());
        System.out.println("状态: " + error.getStatus());

        // 根据错误码查找枚举
        ErrorCode errorByCode = ErrorCode.getByCode(2001);
        System.out.println("\n通过错误码 2001 查找到的错误: " + errorByCode.getMessage());
    }
}